using System;
using System.Text;
using Sirenix.OdinInspector;
using Sirenix.Serialization;

namespace BTEditor
{
    [BTDecorator]
    public class TimeMax : Decorator
    {
        public override Type GetNodeType()
        {
            return typeof(NPBehave.TimeMax);
        }

        public override ErrorType GetIsVaild()
        {
            return BelongNode.IsHaveChild ? ErrorType.None : ErrorType.Error;
        }
        
        protected override void DealField(StringBuilder sb)
        {
            sb.Append($"{limit.ToArgs()},");
            if (argsCountType == ArgsCountType.Two || argsCountType == ArgsCountType.Three)
            {
                sb.Append($"{waitForChildButFailOnLimitReached.ToArgs()},");
                if (argsCountType == ArgsCountType.Three)
                {
                    sb.Append($"{randomVariance.ToArgs()},");
                }
            }
        }
        
        public override int ShowArgsMask => (int) (ArgsCountType.Two | ArgsCountType.Three);
        
        [InfoBox("run the given decoratee. If the decoratee doesn't finish within the limit and randomVariation, the execution fails. If waitForChildButFailOnLimitReached is true, it will wait for the decoratee to finish but still fail.","infoBox")]
        [Title("是否显示节点注释")]
        [LabelText("显示节点注释 ： ")]
        public bool infoBox;
        
        [EnumButton("ShowArgsMask")]
        [HideLabel] 
        [Title("参数选择")]
        public ArgsCountType argsCountType;
        
        [HideLabel] [Title("最大时间")]   [OdinSerialize]
        public float limit = 0.0f;
        
        [HideLabel] [Title("子节点执行超时")]   [OdinSerialize]
        [EnableIf("argsCountType",ArgsCountType.Two)]
        [InfoBox("If waitForChildButFailOnLimitReached is true, it will wait for the decoratee to finish but still fail.")]
        public bool waitForChildButFailOnLimitReached = false;
                
        [HideLabel] [Title("执行差异")] 
        [OdinSerialize]
        [EnableIf("argsCountType",ArgsCountType.Three)]
        public float randomVariance = 0;
    }
}